import time
from data011.Page.Page1 import Page1
from selenium.webdriver.common.by import By
from data011.Tools.Tools import Tools
class Page2(Page1):
    # 点击请登录     class="headerLogin"
    headerLogin_loc = (By.CLASS_NAME,'headerLogin')
    def headerLogin(self):
        self.click(self.headerLogin_loc)
    # 断言1
    dy1_loc = (By.XPATH,'//*[@id="loginform"]/div/div/div/div/div[1]/div[1]/a[1]')
    def dy1(self):
        return self.text(self.dy1_loc)
    # 账号
    userName_loc = (By.ID,'userName')
    def userName(self):
        self.send_keys(self.userName_loc,'17518836160')
    # 密码
    password_loc = (By.ID,'password')
    def password(self):
        self.send_keys(self.password_loc,'123456Aa')
    # 登录
    dl_click = (By.ID,'save')
    def dl(self):
        self.click(self.dl_click)
    # 点击确定  bindSub
    bindSub_loc = (By.ID,'bindSub')
    def bindSub(self):
        self.click(self.bindSub_loc)
    dy2_loc = (By.XPATH,'/html/body/div[2]/div/div[1]/div/p/span')
    def dy2(self):
        return self.text(self.dy2_loc)
    # 输入商品名称 wd
    wd_loc = (By.ID,'wd')
    def wd(self):
        self.send_keys(self.wd_loc,'茅台')
    # 点击搜索 search-btn
    search_loc = (By.CLASS_NAME,'search-btn')
    def search(self):
        self.click(self.search_loc)
    # 点击商品
    click_sp_loc = (By.XPATH,'/html/body/div[6]/div/div[2]/div[5]/ul/li[1]/div[2]/div[1]/a/img')
    def click_sp(self):
        self.click(self.click_sp_loc)
    # 点击加入购物车
    addToCart_loc = (By.ID,'addToCartForDetail')
    def addToCart(self):
        self.click(self.addToCart_loc)
    # 点击查看购物车   detail_chakangouwuche
    chakang_loc = (By.NAME,'detail_chakangouwuche')
    def chakang(self):
        self.click(self.chakang_loc)

    def test_jiouxian_02(self):
        Tools().Log()
        self.open_url('https://www.jiuxian.com/')
        self.headerLogin()
        time.sleep(2)
        print('进入登录页面断言:',self.dy1())
        assert self.dy1() == '帐号登录'
        time.sleep(2)
        self.userName()
        self.implicitly_wait(10)
        self.password()
        time.sleep(10)
        self.dl()
        self.bindSub()
        time.sleep(4)
        print('登录成功断言:', self.dy2())
        assert self.dy2() == 'jxw357734689'
        time.sleep(5)
        self.wd()
        self.search()
        time.sleep(2)
        self.click_sp()
        # 窗口切换
        self.handles()
        self.addToCart()
        self.chakang()
        time.sleep(3)







